package p5;

import java.util.Arrays;

/**
 * @author krystal
 * @date 2022/11/10 14:12
 */
public class Demo7 {
    public static void main(String[] args) {
        int[] arr={4,7,2,8,9,1,3};
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void bubbleSort(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length-i-1; j++) {
                if(arr[j] > arr[j+1]){
                    int tmp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=tmp;
                }
            }
        }
    }
}
